<?php
  //echo $this->Html->script('jquery.multiselect');
  //echo $this->Html->css('calendar/fullcalendar');
  //echo $this->Html->css('jquery.multiselect');
  echo $this->Html->script('user_globel');
?>
<script type="text/javascript">
  /*$(document).ready(function() {
     $("#MessageCustomer").multiselect({
        noneSelectedText: 'Select Customers',
        selectedText: "# Customer Selected"
     });
  });*/
</script>
<style type="text/css">
    .chzn-container-multi .chzn-choices {
        width: 510px !important;
    }
</style>
<div id="content">
	<!--  start page-heading -->
	<div id="page-heading">
		<h1><?php echo __('Send Message'); ?></h1>
	</div>
	<!-- end page-heading -->
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
  	<tr>
  		<th rowspan="3" class="sized">
          <?php echo $this->Html->image('/images/shared/side_shadowleft.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
      </th>
  		<th class="topleft"></th>
  		<td id="tbl-border-top">&nbsp;</td>
  		<th class="topright"></th>
  		<th rowspan="3" class="sized">
          <?php echo $this->Html->image('/images/shared/side_shadowright.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
      </th>
  	</tr>
  	<tr>
  		<td id="tbl-border-left"></td>
  		<td>
  		<!--  start content-table-inner ...................................................................... START -->
    		<div id="content-table-inner">
      			<!--  start table-content  -->
      			<div id="table-content">
                 <?php echo $this->Form->create('Message'); ?>
                    <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                    		<tr>
                    			 <th valign="top">Subject :</th>
                    			 <td>
                              <?php echo $this->Form->input('subject', array('label' => false, 'div' => false,'class'=>'input-form','style'=>'width:500px')); ?>     
                           </td>
                    			 <td></td>
                    		</tr>
                                <?php
                                if(empty($customer_select)){ ?>
                                <tr>
                                    <th valign="top">Send to</th>
                                    <td>
                                    <?php 
                                        $temp = array();
                                        $temp['customer']="Specific customer";
                                        $temp['group']="Shopper groups";
                                        $temp['type'] = "Customer Types";
                                    ?>
                                    <?php echo $this->Form->input('send_to', array('options' => $temp,'id'=>'send_to', 'label' => false, 'div' => false,'class'=>'chosen','selected'=>'customer', 'empty' => '--Select send type--')); ?>     
                                    </td>
                                    <td></td>
                    		</tr>
                                <?php }
                                ?>
                    		<tr>
                    			 <th valign="top">Customers :</th>
                    			 <td>
                                             <script type="text/javascript">
                                                $(document).ready(function(){
                                                    var selected_group = new Array();
                                                    <?php foreach ($customer_select as $value) { ?>
                                                        selected_group.push(parseInt("<?=$value?>"));
                                                    <?php } ?>
                                                    $('#cus option').each(function(){
                                                        if(check_in_array($(this).val(), selected_group)==1){
                                                            $(this).attr('selected', "selected");
                                                        }
                                                    });
                                                    $('#cus').trigger("liszt:updated");
                                                    
                                                    $("#groups_chzn").addClass("hidden");
                                                    $("#types_chzn").addClass("hidden");
                                                    $('#send_to').chosen().change(function(){
                                                        if($(this).val()=="customer"){
                                                            $("#cus_chzn").removeClass("hidden");
                                                            $("#groups_chzn").addClass("hidden");
                                                            $("#types_chzn").addClass("hidden");
                                                        }else if($(this).val()=="type"){
                                                            $("#types_chzn").removeClass("hidden");
                                                            $("#groups_chzn").addClass("hidden");
                                                            $("#cus_chzn").addClass("hidden");
                                                        }else if($(this).val()=="group"){
                                                            $("#groups_chzn").removeClass("hidden");
                                                            $("#cus_chzn").addClass("hidden");
                                                            $("#types_chzn").addClass("hidden");
                                                        }
                                                    });
                                                    
                                                    
                                                });
                                            </script>
                              <?php 
                                  $customer = array();
                              		foreach($customers as $value):
                                     $customer[$value['Customer']['id']] = $value['Customer']['f_name']." ".$value['Customer']['l_name'];
                                  endforeach;
                              ?>
                              <?php echo $this->Form->input('customer', array('id'=>"cus",'options' => $customer, 'label' => false, 'div' => false, 'multiple' => true,'data-placeholder'=>'Select Customer', 'class' => 'chosen med')); ?>     
                              <?php echo $this->Form->input('groups', array('id'=>"groups",'options' => $customer_groups, 'label' => false, 'div' => false, 'multiple' => true,'data-placeholder'=>'Select groups', 'class' => 'hidden chosen med')); ?>     
                              <?php echo $this->Form->input('types', array('id'=>"types",'options' => $customer_types, 'label' => false, 'div' => false, 'multiple' => true,'data-placeholder'=>'Select types', 'class' => 'hidden chosen med')); ?>     
                           </td>
                    			 <td></td>
                    		</tr>
                    		<tr>
                    			 <th valign="top">Existing Template :</th>
                    			 <td>
                                        <?php 
                                            $template = array();
                                                foreach($templates as $value):
                                               $template[$value['Message']['id']] = $value['Message']['name'];
                                            endforeach;
                                        ?>
                                        <?php echo $this->Form->input('template_id', array('options' => $template, 'label' => false, 'div' => false,'class'=>'chosen', 'empty' => '--Select Template--')); ?>     
                           </td>
                    			 <td></td>
                    		</tr>
                                <tr>
                                    <th valign="top">Language</th>
                                    <td>
                                    <?php 
                                        $temp = array();
                                        $temp['English']="English";
                                        $temp['Arabic']="Arabic";
                                    ?>
                                    <?php echo $this->Form->input('language', array('options' => $temp, 'label' => false, 'div' => false,'class'=>'chosen', 'empty' => '--Select Language--')); ?>     
                                    </td>
                                    <td></td>
                    		</tr>
                    		<tr id="template-preview">
                          <th valign="top">Preview :</th>
                          <td>
<script type="text/javascript">
// O2k7 skin
/*
tinyMCE.init({
        // General options
        mode : "exact",
        elements : "content_area",
        theme : "advanced",
        skin : "o2k7",
        width : "800",
        plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Example content CSS (should be your site CSS)
        content_css : "/loyalty_virgin/css/admin/screen.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "/loyalty_virgin/js/tiny_mce/plugins/template/editor_plugin.js",
        external_link_list_url : "/loyalty_virgin/js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "/loyalty_virgin/js/tiny_mce/plugins/media/editor_plugin.js",

        // Replace values for the template plugin
        template_replace_values : {
                username : "Some User",
                staffid : "991234"
        }
});*/
</script>
                            <?php echo $this->Form->input('Message.message', array('label' => false, 'style'=>'width:500px;height:250px','div' => false,'type'=>'textarea', 'id' => 'content_area')); ?>       
                          </td>
                          <td></td>
                    		</tr>
                        <tr>
                        	<th>&nbsp;</th>
                        	<td valign="top">
                                <?php echo $this->Form->submit(__('Send', true), array('label' => false, 'div' => false, 'class' => 'submit-button'));?>
                         		    <a href="#" onclick="history.back(-1)" class="cancel-button">Cancel</a>
                          </td>
                        	<td></td>
                        </tr>
                      </table>
                    <?php echo $this->Form->end(); ?>
                </div>
        		</div>
      <!--  end content-table  -->
    		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery("#messagesMenu").addClass("current");
  });
</script>